FUNCTION_BLOCK LCB_PosToUnit
TITLE = 'LCB_PosToUnit'
//
// This FB uses the transmitted machine parameters and converts a position in [inc]
// into a position in the REAL unit OF the machine.
// Versionshistory:
// 1.0 Ersterstellung E.Dittmann

VERSION : '1.0'
AUTHOR  : 'Lenze'
FAMILY  : 'LCB'
NAME : 'PosToUni'
KNOW_HOW_PROTECT

VAR_INPUT
    AxisData                : BLOCK_DB;                             // AxisData DB-Nr
    diPosIn_p               : DINT;                                 // Positionvalue in increments
END_VAR

VAR_OUTPUT
    rPositionOutUnits       : REAL;                                 // Positionvalue in units
    xLimit                  : BOOL;                                 // Limit Error   
END_VAR

VAR
    dwTemp                  :DWORD;
    rTemp                   :REAL;
 
END_VAR

        
BEGIN
    dwTemp              :=AxisData.dd72;   // AxisData.rPosToUnits
    rTemp               :=DWORD_TO_REAL(dwTemp);
    rPositionOutUnits   :=DINT_TO_REAL(diPosIn_p) *  rTemp;
    IF  (rPositionOutUnits >= 2147483647.0)  THEN
        xLimit := TRUE;
        rPositionOutUnits := 2147483647;
    ELSIF  (rPositionOutUnits <= -2147483647.0) THEN
        xLimit := TRUE;
        rPositionOutUnits := -2147483647;
    ELSE
        xLimit := FALSE;
    END_IF;

END_FUNCTION_BLOCK


